package com.kanshu.ksgb.fastread.doudou.module.login.activity;

import android.graphics.Color;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.View;

import com.alibaba.android.arouter.facade.annotation.Route;
import com.gyf.barlibrary.ImmersionBar;
import com.kanshu.ksgb.fastread.doudou.R;
import com.kanshu.ksgb.fastread.doudou.app.constants.ARouterConfig;
import com.kanshu.ksgb.fastread.doudou.base.baseui.BaseActivity;
import com.kanshu.ksgb.fastread.doudou.common.util.ARouterUtils;
import com.kanshu.ksgb.fastread.doudou.common.util.ActivityMgr;

import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * 单点登录弹出对话框
 * 作者    wcy
 * 时间    2018/11/18 22:15
 * 文件    doudou
 * 描述
 */
@Route(path = ARouterConfig.SSO_LOGIN)
public class SSOLoginActivity extends BaseActivity {

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        goneTitlebar(true);
        setContentView(R.layout.activity_sso_login_layout);
        ButterKnife.bind(this);
        findViewById(R.id.root).setBackgroundColor(Color.TRANSPARENT);
    }

    @Override
    protected void initStatusbar() {
        try {
            mImmersionBar = ImmersionBar.with(this);
            mImmersionBar.keyboardEnable(true);
            mImmersionBar.init();
            if (ImmersionBar.isSupportStatusBarDarkFont())
                mImmersionBar.statusBarDarkFont(true).init();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    @Override
    public boolean isSupportSwipeBack() {
        return false;
    }

    @OnClick({R.id.cancel, R.id.sure})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.cancel:
                ARouterUtils.toActivity(ARouterConfig.HOME_PAGE);
                break;
            case R.id.sure:
                if(!ActivityMgr.getInstance().existPageByTag(ARouterConfig.PageTagParams.HOME_PAGE)){   // 主页不存在，打开主页再打开登录页面
                    ARouterUtils.toActivity(ARouterConfig.HOME_PAGE);
                }
                ARouterUtils.toActivity(ARouterConfig.PERSONAL_LOGIN_IN, "phone", "");
                break;
        }
        finish();
    }

    @Override
    protected void onBeforeSetContentView() {
        if (isNeedRemoveWindowBackground()) {
            getWindow().setBackgroundDrawable(null);
        }
    }

    @Override
    public void onBackPressed() {
    }

    @Override
    protected String getSpecifyTag() {
        return ARouterConfig.PageTagParams.SSO_LOGIN_PAGE;
    }

    @Override
    protected boolean isNeedRemoveWindowBackground() {
        return false;
    }
}
